"""
环境配置和依赖安装脚本
运行此脚本前请确保已安装Python 3.7+
"""

import subprocess
import sys
import os

def install_requirements():
    """安装必要的Python包"""
    requirements = [
        'pandas>=1.3.0',
        'numpy>=1.21.0',
        'snownlp>=0.12.3',
        'jieba>=0.42.1',
        'scikit-learn>=1.0.0',
        'scipy>=1.7.0',
        'matplotlib>=3.5.0',
        'wordcloud>=1.8.0',
        'textblob>=0.17.0'
    ]
    
    print("正在安装依赖包...")
    for package in requirements:
        try:
            subprocess.check_call([sys.executable, "-m", "pip", "install", package])
            print(f"✓ {package} 安装成功")
        except subprocess.CalledProcessError:
            print(f"✗ {package} 安装失败")
    
    print("依赖安装完成！")

def create_directories():
    """创建必要的目录结构"""
    directories = [
        'data/raw',           # 原始数据
        'data/processed',     # 处理后数据
        'data/dictionaries',  # 词典文件
        'results',           # 结果文件
        'logs'               # 日志文件
    ]
    
    for directory in directories:
        os.makedirs(directory, exist_ok=True)
        print(f"✓ 创建目录: {directory}")

def download_resources():
    """下载必要的语言资源"""
    import jieba
    # jieba会自动下载词典，第一次运行时会自动处理

if __name__ == "__main__":
    print("=== 环境配置开始 ===")
    install_requirements()
    create_directories()
    download_resources()
    print("=== 环境配置完成 ===")